import { thin } from "../thin3.mjs";

export default function collectdata(container) {
  let data = {};
  if (container)
    thin("input,textarea,select,multiselect", container).each((e) => {
      if (e.name) {
        // console.log({ element: e, value: e.value });
        switch (e.tagName) {
          case "MULTISELECT":
            data[e.name] = e.thin_selected;
            break;
          default:
            if (e.type === "checkbox") {
              data[e.name] = e.checked;
            } else if (e.type === "file") {
            } else {
              data[e.name] = e.value?.trim();
            }
        }
      }
    });
  return data;
}

export function collectfile(container) {
  console.log({ container });
  let data = {};
  if (container)
    thin("input[type='file']", container).each((e) => {
      data[e.name] = { files: e.files, path: e.thin_path };
    });
  return data;
}
